---
title: Use Scoring Code with AWS Lambda
description: Learn how to integrate Scoring Code models with AWS Lambda.

---

# Use Scoring Code with AWS Lambda {: #use-scoring-code-with-aws-lambda }

This topic describes how you can use DataRobot’s Scoring Code functionality to download a model's Scoring Code and deploy it using AWS Lambda.

DataRobot automatically runs code generation for those models that support it, and indicates code availability with an icon on the Leaderboard.

![](images/int_uscmwal_large_014.png)

This option allows you to download validated Java Scoring Code for a predictive model without approximation; the code is easily deployable in any environment and is not dependent on the DataRobot application.

### Why deploy on AWS Lambda {: #why-deploy-on-aws-lambda }

While DataRobot provides its own scalable prediction servers that are fully integrated with the platform, there are multiple reasons why you would want to deploy on AWS Lambda:

* Company policy or governance decision.

* Serverless architecture.

* Cost reduction.

* Custom functionality on top of the DataRobot model.

* The ability to integrate models into systems that cannot communicate with the DataRobot API. In this case, AWS Lambda can be used either as a primary means of scoring for fully offline systems or as a backend for systems that are using the DataRobot API.

### Download Scoring Code {: #download-scoring-code }

The first step to deploying a DataRobot model to AWS Lambda is to download the Scoring Code JAR file from the [Leaderboard](sc-download-leaderboard) or the [deployment](sc-download-deployment).

![](images/sc-download-1.png)

Next, create your own Lambda scoring project.

![](images/int_uscmwal_large_009.png)

In `pom.xml`, change the path to the downloaded JAR file.

![](images/lambda-sc-1.png)

### Compile the project {: #compile-the-project }

After downloading Scoring Code and creating a Lambda project, finalize the setup by compiling the project.

To start with, find this line in `CodeGenLambdaExample.java` and impute with your model ID:

```
public static String modelId = "<Put exported Scoring Code model\_id here>";
```

If you have a classification model, you need to use the IClassificationPredictor interface:

```
public static IClassificationPredictor model;
```

If it’s a regression model, use the the IRegressionPredictor interface:

```
public static IRegressionPredictor model;
```

Now you can run the maven command `mvn package` to compile the code. The packaged JAR file will appear in the target folder of the project.

###  Deploy to AWS Lambda {: #deploy-to-aws-lambda }

To deploy to AWS Lambda, use the following steps:


1. Select **Create function** from the AWS menu:

    ![](images/int_uscmwal_large_006.png)

2. Choose Java 11 or Java 8 to create the Lambda function:

    ![](images/int_uscmwal_large_011.png)

3. Enter a name for the function.

    ![](images/int_uscmwal_large_013.png)

4. Configure Lambda permissions as shown below.

    ![](images/int_uscmwal_large_004.png)

5. Upload the compiled JAR file to Lambda. View the upload options below.

    ![](images/int_uscmwal_large_012.png)

    You can view the JAR file location below.

    ![](images/int_uscmwal_large_008.png)

6. Choose the Lambda handler for your Java package name:

    ![](images/int_uscmwal_large.png)

The setup is now complete. DataRobot recommends testing the function to see that the deployment is working as intended.

### Test the Lambda function {: #test-the-lambda-function }

To test the Lambda function:

1. Go to the TEST event configuration page.

    ![](images/int_uscmwal_large_007.png)

2. Add JSON with features as a test event.

    ![](images/int_uscmwal_large_005.png)

3. Click the **Test** button.

    ![](images/int_uscmwal_large_003.png)

After testing is complete, you can integrate with the AWS API Gateway or other services so that data is sent to the Lambda function and it returns results.
